#!/bin/sh
# Bug reports and comments to Igor.Ermolaev@intel.com
args=("$@")
for i in "${!args[@]}";do
   if [ "${args[$i]}" == '--' ];then
      args=("${args[@]:0:$i}" '--' "${args[@]:$i}")
      break
   elif [ "${args[$i]}" == mpirun ] || [ "${args[$i]}" == mpiexec ] || [ "${args[$i]}" == mpiexec.hydra ];then
      args=("${args[@]:0:$i}" '--' '--' "${args[@]:$i}")
      break
   fi
done
eval glbs=($TRACING_SDK_SDE_MPI_ARGS)
unset lidx
for i in "${!glbs[@]}";do
   if [ "${glbs[$i]}" == '--' ];then lidx=$i;break; fi
done
if [ -n "$lidx" ];then
   glbs[$lidx]='--local--'
   args=("${glbs[@]}" "${args[@]}")
else
   args=("${glbs[@]}" --local-- "${args[@]}")
fi
unset i lidx glbs
exec $(dirname $(readlink -f ${BASH_SOURCE[0]:-$0}))/mpirun_inj $(dirname $(readlink -f ${BASH_SOURCE[0]:-$0}))/run_sde "${args[@]}"
